package com.david.mydemo.ctl_ftp.task;

import com.david.mydemo.ctl_ftp.service.impl.SysLogService;
import com.david.mydemo.util.DateUtils;
import com.david.mydemo.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class TaskService {

    @Autowired
    private SysLogService sysLogService;

    private String lastDateStr;

    /**
     * 导出xml日志文件，上传到审计ftp服务器
     */
    @Scheduled(cron = "0 */5 * * * *")
//    @Scheduled(cron = "*/5 * * * * *")
    public void exportFtpXmlDataTask() {
        long start = System.currentTimeMillis();
        log.info("导出xml日志文件，上传到审计ftp服务器。开始执行。。。");
        if (StringUtils.isEmpty(lastDateStr)) {
            lastDateStr = DateUtils.get5MinAgoDateTime();
        }
        lastDateStr = sysLogService.exportFtpXmlData(lastDateStr);
        log.info("导出xml日志文件，上传到审计ftp服务器。结束执行。。。耗时：{}秒。", (System.currentTimeMillis() - start) / 1000);
    }

}
